<template>
	<view class="test">
		<swiper class="testSwiper" vertical :interval="3000" :duration="1000" @change="change">
			<swiper-item v-for="(item,index) in arr" :key="index" >
				<view class="swiper-item" @click.stop="clickVideo">
					<view class="">{{item.title}}</view>
					<video autoplay :id="item.id+''+answerIndex" loop v-if="answerArr[answerIndex].videoUrl" :src="answerArr[answerIndex].videoUrl" :controls="false"></video>
				</view>
			</swiper-item>
		</swiper>
	</view>
</template>

<script>
	import { hotMoreList,answerAboutHot,operAboutHot,dislikeHot } from "@/api/school.js"
	import { focusUser } from "@/api/index.js"
	import { payBeforeTip } from "@/utils/common.js"
	export default {
		data() {
			return {
				videoContxt:'',
				paseV:false,
				answerArr:[],
				arr:[],
				answerIndex:0,
				k:0
			}
		},
		components:{
			
		},
		
		onLoad() {
			this.getInitData()
		},
		onShow(){
		},
		onHide(){
			// // #ifdef MP
			// this.dataList[this.k].state = 'pause';
			// uni.createVideoContext(this.dataList[this.k]._id+''+this.k,this).pause()
			// // #endif
			// // #ifdef H5
			// if(this.isClick){
			// 	this.dataList[this.k].state = 'pause';
			// 	uni.createVideoContext(this.dataList[this.k]._id+''+this.k,this).pause()
			// 	audo.pause()
			// }
			// // #endif
			console.log('到后台');
		},
		methods: {
			clickVideo(){
				this.videoContxt=uni.createVideoContext(this.arr[this.k].id+''+this.answerIndex, this)
				this.paseV=!this.paseV
				console.log('点击',this.paseV,this.videoContxt)
				if(this.paseV){
					this.videoContxt.pause()
				}else{
					this.videoContxt.play()
				}
				
			},
			change(event){
				this.k=event.detail.current
				this.getAnswer(this.arr[event.detail.current].id,'init')
			},
			// 获取提问列表数据
			getInitData(){
				// 这个方法主要就是用来第一次进入视频播放时用来处理的
				let param={
					page:1,
					size:10,
					objectId:'',
				}
				hotMoreList(param).then((res)=>{
					console.log('res===',res)
					if(res.code==100000){
						if(res.data.rows.length==0){
							uni.showToast({
								title:'已经到底了哦',
								icon:'none'
							})
							return
						}
						this.arr=this.arr.concat(res.data.rows)
						this.getAnswer(this.arr[0].id,'init')
					}
				})
			},
			// 获取回答列表
			getAnswer(id,type){
				uni.showLoading({
					title:'加载中',
					mask:true
				})
				this.pauseV=true
				let param={
					page:this.page,
					size:this.pageSize,
					questionId:id
				}
				answerAboutHot(param).then((res)=>{
					uni.hideLoading()
					if(res.code==100000){
						if(type=='init'){
							this.answerIndex=0
							this.answerArr=[]
						}
						this.pauseV=false
						this.answerArr=this.answerArr.concat(res.data.rows)
					}
				})
			},
		}
	}
</script>
<style lang="scss">
	page{
		width: 100%;
		height: 100%;
	}
</style>
<style scoped lang="scss">
	.test,
	.testSwiper{
		width: 100%;
		height: 100%;
	}
	.swiper-item{
		width: 100%;
		height: 100%;
		padding: 100rpx 0;
		box-sizing: border-box;
		video{
			width: 100%;
		}
	}
</style>
